package com.freewater.cargotracker.infrastructure.persistence.mybatis.converter;

import com.freewater.cargotracker.domain.model.location.Location;
import com.freewater.cargotracker.domain.model.location.UnLocode;
import com.freewater.cargotracker.infrastructure.persistence.mybatis.dbobject.LocationPO;

public class LocationConverter {

    public static LocationPO serialize(Location location) {
        if (location == null) {
            return null;
        }
        LocationPO locationPO = new LocationPO();
        locationPO.setId(location.getId());
        locationPO.setName(location.getName());
        locationPO.setUnLocode(location.getUnLocode().getCode());
        return locationPO;
    }

    public static Location deserialize(LocationPO locationPO) {
        if (locationPO == null) {
            return null;
        }
        Location location = new Location(new UnLocode(locationPO.getUnLocode()), locationPO.getName());
        location.setId(locationPO.getId());
        return location;
    }
}
